﻿@model ICollection<IXfmOption>
@{
    ViewData["Title"] = "Options数据";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
@section Styles{
    <link href="/plugins/monaco-editor/min/vs/editor/editor.main.css" data-name="vs/editor/editor.main" rel="stylesheet" />
<style>
    #bj .card-body{
        padding:0;
    }
</style>
}
<div class="container-fluid">
    @foreach (var item in Model)
    {
        <div class="row">
            <div class="col-md-6">
                <card title="key:@(item.Key)">
                    <bt onclick="reload('@(item.Key)')" color="Info">从json文件重新加载</bt>
                    <bt onclick="reset('@(item.Key)')" color="Info">修改配置，并同步json文件</bt>
                    <bt onclick="edit('@(item.Key)')" color="Danger">编辑</bt>
                    <ul>
                        @foreach (var vl in item.GetValue<NavModel>().NavNodes)
                        {
                            <li>@vl.Title</li>
                            if (vl.Childs != null && vl.Childs.Count > 0)
                            {
                                <ul>
                                    @foreach (var child in vl.Childs)
                                    {
                                        <li>@child.Title <span class="text-success">@child.Link</span></li>
                                    }
                                </ul>
                            }
                        }
                    </ul>
                </card>
            </div>
            <div class="col-md-6">
                <card title="编辑" tools="maximize" id="bj">
                    <div id="editor_1" style="border:1px solid grey;height:600px;"></div>
                </card>

            </div>
        </div>
    }
</div>
@section Scripts{
    <script>var require = { paths: { 'vs': '/plugins/monaco-editor/min/vs' } };</script>
    <script src="/plugins/monaco-editor/min/vs/loader.js"></script>
    <script src="/plugins/monaco-editor/min/vs/editor/editor.main.nls.zh-cn.js"></script>
    <script src="/plugins/monaco-editor/min/vs/editor/editor.main.js"></script>
    <script>
        var editor = monaco.editor.create(document.getElementById('editor_1'), {

            //value: [
            //    'function x() {',
            //    '\tconsole.log("Hello world!");',
            //    '}'
            //].join('\n'),
            //value: [''].join('\n'),
            language: 'json',
            theme: "vs-dark",
            automaticLayout: true,//自动更改宽度
        });
        //console.log(editor);
        function reload(key) {
            $.post("/OptionTest/Reload", { key: key }, function (d) {
                if (d.ret === 0)
                    location.reload();
                else
                    alert(d.msg);
            })
        }
        function reset(key) {
            $.post("/OptionTest/Reset", { key: key }, function (d) {
                if (d.ret === 0)
                    location.reload();
                else
                    alert(d.msg);
            })
        }
        function edit(key) {
            //editor.colorize("test", "json");

            $.get("/OptionTest/Edit", { key: key }, function (d) {
                if (d.ret === 0) {
                    editor.setValue(d.msg);
                } else {
                    alert(d.msg);
                }
            })
        }
    </script>


    <script>


                    //$('#bj').on('maximized.lte.cardwidget', resize);
                    //$('#bj').on('minimized.lte.cardwidget', resize);
    </script>
}

